var images = ['images/img01.png','images/img02.png','images/img03.png','images/img04.png','images/0.png','images/0.png','images/校训.png']

function preloadimages(arr)
{
    var newimages = []
    var arr = (typeof arr != "object") ? [arr] :arr
    for(var i = 0; i<arr.length;i++)
    {
        newimages[i] = new Image()
        newimages[i].src = arr[i]
    }
    console.log("2")
}
preloadimages(images)

var flag = 0   //圆点1的标志位
var num1 = 1    //圆点2的标志位
var num2 = 1    //圆点3的标志位
var major = document.getElementById("major")
var set = setInterval(change, 3000)
var canle       //serInterval返回的ID
var temp = 0
var bg = 1 

var count =2 ;
function change()
{
     major.style.backgroundImage = "url('images/img0" + count +".png')";
    count++
    if(count > 4)
    {
        count = 1
    }
}


//鼠标滚轮事件
var scrollFunc = function(e) {
    var direct = 0;   
    e = e || window.event;   
    if(e.stopPropagation) e.stopPropagation();   
    else e.cancelBubble = true;   
    if(e.preventDefault) e.preventDefault();      
    else e.returnValue = false;      
    if(e.wheelDelta)
 {  //判断浏览器IE，谷歌滑轮事件   
    if(e.wheelDelta > 0)        //当滑轮向上滚动时 
    {   
       
        if( bg == "url('images/0.png')" )
           {
               
                if(temp == 1)
                {   //与圈1同样的功能
                    major.style.backgroundImage  = "url('images/img01.png')";
                    bg = 1
                    count = 2
                    canle = setInterval(change,3000);
                    document.getElementById("school").style.display = "block"
                    document.getElementById("second").style.display = "none"
                    document.getElementById("cont").style.display = "none"
                    temp = 0
                    num1 = num2 = 1
                    flag = 0
                }
            }
        if( bg  == "url('images/1.png')")
            {       //与圈2同样的功能
                    clearInterval(set);
                    clearInterval(canle)
                     temp  = 1
                     flag = num2 =  1
                    major.style.backgroundImage = bg = "url('images/0.png')";
                    document.getElementById("cont").style.display = "none"
                    document.getElementById("school").style.display = "none"
                    document.getElementById("second").style.display = "block";
            }
        
    } 
         
    if(e.wheelDelta < 0)        //当滑轮向下滚动时
    {    
        if(bg == "url('images/0.png')")  
            {   //与圈3同样的功能
                clearInterval(set);
                clearInterval(canle)
                temp = 1
                flag = num1 = 1
                major.style.backgroundImage = bg = "url('images/1.png')";
                document.getElementById("second").style.display = "none";
                document.getElementById("school").style.display = "none"
                document.getElementById("cont").style.display = "block"
                
            }  
            if(bg == 1)    
            {   //与圈2同样的功能
                clearInterval(set)
                clearInterval(canle)
                flag = num2 = 1
                temp = 1
                major.style.backgroundImage = bg = "url('images/0.png')";
                document.getElementById("cont").style.display = "none"
                document.getElementById("school").style.display = "none"
                document.getElementById("second").style.display = "block";
            }
                     
    }
} 
    else if(e.detail) {  //Firefox滑轮事件
                  
        if(e.detail > 0) 
        { //当滑轮向上滚动时
                      
            if (bg == "url('images/0.png')") {

                if (temp == 1) {   //与圈1同样的功能
                    major.style.backgroundImage = "url('images/img01.png')";
                    bg = 1
                    count = 2
                    canle = setInterval(change, 3000);
                    document.getElementById("school").style.display = "block"
                    document.getElementById("second").style.display = "none"
                    document.getElementById("cont").style.display = "none"
                    temp = 0
                    num1 = num2 = 1
                    flag = 0
                }
            }
            if (bg == "url('images/1.png')") {       //与圈2同样的功能
                clearInterval(set);
                clearInterval(canle)
                temp = 1
                flag = num2 = 1
                major.style.backgroundImage = bg = "url('images/0.png')";
                document.getElementById("cont").style.display = "none"
                document.getElementById("school").style.display = "none"
                document.getElementById("second").style.display = "block";
            }

        }        
        if(e.detail < 0) 
        { //当滑轮向下滚动时
                      
            if (bg == "url('images/0.png')") {   //与圈3同样的功能
                clearInterval(set);
                clearInterval(canle)
                temp = 1
                flag = num1 = 1
                major.style.backgroundImage = bg = "url('images/1.png')";
                document.getElementById("second").style.display = "none";
                document.getElementById("school").style.display = "none"
                document.getElementById("cont").style.display = "block"

            }
            if (bg == 1) {   //与圈2同样的功能
                clearInterval(set)
                clearInterval(canle)
                flag = num2 = 1
                temp = 1
                major.style.backgroundImage = bg = "url('images/0.png')";
                document.getElementById("cont").style.display = "none"
                document.getElementById("school").style.display = "none"
                document.getElementById("second").style.display = "block";
            }      
        }
    }
    return false
}

if(document.addEventListener) {
    document.addEventListener('DOMMouseScroll', scrollFunc, false);
}
//IE及其他浏览器
window.onmousewheel = document.onmousewheel = scrollFunc;


//获取第一个圆点并绑定事件
var dotted1 = document.getElementById("circle01")
dotted1.onclick = function()
{
    if(flag == 1)
    {
    bg = 1
    major.style.backgroundImage = "url('images/img01.png')";
    count = 2
    canle = setInterval(change,3000);
    document.getElementById("school").style.display = "block"
    document.getElementById("second").style.display = "none"
    document.getElementById("cont").style.display = "none"
    flag = 0
    num1 = num2 = 1
    }
   
}

//获取第二个圆点并绑定事件
var dotted2 = document.getElementById("circle02")
 dotted2.onclick = function()
 {
    if(num1 == 1){
    clearInterval(set);
    clearInterval(canle)
    flag = num2 = 1
    major.style.backgroundImage = bg =  "url('images/0.png')";
    document.getElementById("cont").style.display = "none"
    document.getElementById("school").style.display = "none"
    document.getElementById("second").style.display = "block";
    num1 = 0
    temp = 1
    }
}

//获取第三个圆点并绑定事件
var dotted3 = document.getElementById("circle03")
dotted3.onclick = function()
{
    if(num2 == 1)
    {
    clearInterval(set)
    clearInterval(canle)
    flag = num1 = 1
    major.style.backgroundImage = bg =  "url('images/1.png')";
    document.getElementById("second").style.display = "none";
    document.getElementById("school").style.display = "none"
    document.getElementById("cont").style.display = "block"
    num2 = 0
    }
}


//获取搜索框并绑定事件
var search = document.querySelector(".search")
//获得焦点
search.onfocus = function (){
    if(search.value === "请输入搜索内容" || search.value === "全部" || search.value === "期刊" || search.value === "学术论文" || search.value === "会议" ||  search.value === "专利" || search.value === "标准" || search.value === "成果"  )
    {
        search.value = ""
    }
    this.style.color = "#333"
}
//失去焦点
search.onblur = function lost()
{
    if(search.value === "")
    {
        search.value = "请输入搜索内容"
    }
    this.style.color = "#999"
}


//获取“opt"的"li"子节点，注册onmouseover事件
var list_option = document.getElementById("opt").getElementsByTagName("li")
for(var i = 0; i < list_option.length; i++)
{
    list_option[i].onmouseover = function()
    {   
       
        var text =this.firstChild.nodeValue
        search.value = text
        search.style.color = "#999"
        search.blur()
        
    }
}

var phone = document.getElementById("phone")
var photo = document.getElementById("photo")
var pp = document.getElementById("pp")
var Text = document.createTextNode("800-820")
var aside = document.getElementById("pww").getElementsByTagName("li")
phone.appendChild(Text)
for(var i = 0; i < aside.length; i++)
{
    aside[i].setAttribute("data-index", i)
}
for( var j = 0;j < aside.length;j++)
{

    aside[j].onmouseover = function()
    {
        if( this.getAttribute("data-index") == 0){
            
            phone.style.backgroundColor = "rgb(255,255,255,0.4)"
            phone.style.display = "block"
            phone.style.color = "#0b0c0c"
        }
        else
        {
            photo.style.display = "block"
            pp.src = "images/p" + this.getAttribute("data-index") + ".png"
        }
        
    }
    aside[j].onmouseout = function()
    {
        // if(this.getAttribute("data-index") == 0)
        // {
        //      Text = ""
        // }
        photo.style.display = "none"
        phone.style.display = "none"
    }
}


